package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.ElasticsearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/*** @author xl
 * @version V1.0
 * @Project sms_platform
 * @Package com.qf.listener
 * @Description: ${TODO}
 *@Date 2022/8/29 15:49
 */
@Component
public class SendLogListener {

    @Autowired
    private ElasticsearchService elasticsearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void SendLog(StandardSubmit standardSubmit, Channel channel, Message message) throws IOException {
        //1.保存standardSubmit对象到Es服务器
        elasticsearchService.saveLog(standardSubmit);
        //2.手动Ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
